{include file="public/header" /}
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" id="LAY-user">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" name="start" class="layui-input" onfocus="wk.lay_date(this);" placeholder="上次登录开始日期" >
                    </div>
                        <div class="layui-form-mid">
                        -
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" name="end" class="layui-input" onfocus="wk.lay_date(this);" placeholder="上次登录结束日期" >
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" id="key" class="layui-input" name="key" placeholder="用户名/手机号/邮箱"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                    <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                    <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                    </div>
                </div>
            </div>
            <div>
                <span class="layui-btn-dropdown" style="display:inline-block;">
                    <button class="layui-btn layui-btn-danger" data-toggle="dropdown"><i class="fa fa-wrench"></i> 批量操作 <i class="fa fa-caret-down"></i></button>
                    <ul class="layui-dropdown-menu layui-anim layui-anim-upbit">
                        <li><a  href="javascript:;" class="layuiBtn" data-type="usingAll" id="onAll"><i class="fa fa-check-circle"></i> 批量启用</a></li>
                        <li><a  href="javascript:;" class="layuiBtn" data-type="forbiddenAll" id="offAll"><i class="fa fa-ban"></i> 批量禁用</a></li>
                        <li class="divider"></li><!--分割线-->
                        <li><a  href="javascript:;" class="layuiBtn" data-type="excelAll" id="excel"><i class="fa fa-download"></i> 导出Excel</a></li>
                    </ul>
                </span>
            </div>
        </div>

        <div class="layui-card-body">
            <table id="LAY-table-manage" lay-filter="LAY-table-manage"></table>
            <!--图片模板-->
            <script type="text/html" id="imgTpl">
                <img src="{{d.head_img}}" class="layui-table-img layui-circle" onerror="this.src='/static/admin/images/head_default.gif'"  />
            </script>
            <!--在线模板-->
            <script type="text/html" id="staar">
                {{#  if(d.user_status == 1){ }}
                <a class="layui-badge layui-bg-green" style="width: 50%;">在线</a>
                {{#  } else { }}
                <a class="layui-badge" style="width: 50%;">离线</a>
                {{#  } }}
            </script>
            <!--状态模板-->
            <script type="text/html" id="staBar">
                <input type="checkbox" value="{{d.u_id}}" lay-skin="switch" lay-text="ON|OFF" lay-filter="OnOff"{{ d.is_lock == 1 ? 'checked' : '' }}  >
            </script>
            <!--操作模板-->
            <script type="text/html" id="opeBar">
                <a onclick="wk.layer_show('详情','{:url('view_details')}?id={{d.u_id}}')" class="layui-btn layui-bg-cyan layui-btn-xs" title="查看"><i class="fa fa-bars"></i></a>
                <a onclick="wk.layer_show('编辑用户','{:url('edit_vip')}?id={{d.u_id}}')" class="layui-btn layui-btn-xs" title="编辑"><i class="fa fa-pencil"></i></a>
                <a href="javascript:;" onclick="wk.confirm('{{d.u_id}}','{:url('del_vip')}')" class="layui-btn layui-btn-danger layui-btn-xs" title="删除"><i class="fa fa-trash-o"></i></a>
            </script>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    layui.use(['index', 'table'], function () {
        var $ = layui.$
            , form = layui.form
            , table = layui.table;
        table.render({
            elem: '#LAY-table-manage'
            , url: '{:url("Vip/index")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , even: false //开启隔行背景
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , autoSort: false
            , cellMinWidth: 150
            , height: "full-220"
            , limits: [10, 20, 30, 40, 50]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'LAY-table'
            , cols: [[
                {type: 'checkbox', fixed: 'left',}
                , {type:'numbers', width: 80, title: '序号'}
                , {field: 'nick_name', width: '', title: '用户名', align: 'center'}
                , {field: 'head_img', width: 90, title: '用户头像', align: 'center', templet: '#imgTpl'}
                , {field: 'user_status', width: 120, title: '用户登陆状态', align: 'center', templet: '#staar'}
                , {field: 'email', width: 180, title: '用户邮箱', align: 'center'}
                , {field: 'phone', width: 120, title: '用户手机号', align: 'center'}
                , {field: 'login_num', width: 120, title: '登录次数', sort: true, align: 'center'}
                , {field: 'last_login_ip', width: '', title: '上次登录IP', align: 'center'}
                , {field: 'last_login_time', width: 180, title: '上次登录时间', sort: true, align: 'center',templet:"<div>{{d.last_login_time?layui.util.toDateString(d.last_login_time*1000,'yyyy-MM-dd HH:MM'):''}}</div>"}
                , {field: 'reg_time', width: 180, title: '注册时间',sort: true, align: 'center',templet:"<div>{{d.reg_time?layui.util.toDateString(d.reg_time*1000,'yyyy-MM-dd HH:MM'):''}}</div>"}
                , {field: 'is_lock', fixed: 'right', width: 90, title: '状态', align: 'center', templet: '#staBar'}
                , {fixed: 'right', width: 120, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            ,done: function (res, curr, count) {
                $('.layui-circle').viewer({
                    url: 'data-original',
                });
            }
        });
        //监听状态开关操作
        form.on('switch(OnOff)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 1: num = 2;
            //Vip状态
            wk.status(this.value,num, '{:url("vip_state")}',obj);
        });
        //事件
        var active = {
           forbiddenAll: function(){
                //批量禁用
                wk.batchForbidden(getIds(),2,"{:url('forbiddenVip')}");
            }
            ,usingAll: function(){
                //批量启用
                wk.usingAll(getIds(),1,"{:url('usingVip')}");
            }
            ,excelAll: function(){
                //导出Excel
                wk.excelAll(getIds(),$(".layui-input").serialize(),"{:url('excelVip')}");
            }
        };

        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('LAY-table')
                ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['u_id'])
            });
            return ids;
        }
    });
</script>
</body>
</html>